package com.itheima.contorller;

import com.itheima.common.ResponseResult;
import com.itheima.pojo.po.Hotel;
import com.itheima.pojo.po.PageByName;
import com.itheima.service.HotelService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/hotel")
@RestController
public class HotelController {

    @Autowired
    private HotelService hotelService;
    /**
    * @author luli
    * @Description 根据名字模糊查询并分页
    * @Date 下午 9:56 2023/1/30 0030
    * @Param [pageByName]
    * @return com.itheima.common.ResponseResult<java.util.List<com.itheima.pojo.po.Hotel>>
    **/
    @PostMapping("/name")
    public ResponseResult<List<Hotel>> findByName(@RequestBody PageByName pageByName){
        List<Hotel> hotels = hotelService.findByName(pageByName);
        return ResponseResult.okResult(hotels);
    }
    //根据ID删除
    @DeleteMapping("/delete/{id}")
    public ResponseResult<Boolean> deleteById(@PathVariable("id") Integer id){
        return hotelService.deleteById(id);
    }
    //前端传递Hotel类数据新增
    @PutMapping("/add")
    public ResponseResult<Boolean> addHotel(@RequestBody Hotel hotel){
        return hotelService.addHotel(hotel);
    }
    //前端传递Hotel类数据,根据所传的id进行更新
    @PostMapping("/update")
    public ResponseResult<Boolean> update(@RequestBody Hotel hotel){
        return hotelService.updateHotel(hotel);
    }
}
